<?php

namespace app\ow_test\controller;


use think\Controller;
use think\Db;
use think\Loader;
use think\response\Json;
use function foo\func;
use think\facade\Env;

require_once Env::get('ROOT_PATH') . "extend/Snoopy-2.0.0.tar.gz/Snoopy.class.php";
require_once Env::get('ROOT_PATH') . "extend/simplehtmldom_1_9_1/simple_html_dom.php";

header("Content-type:text/html;charset=UTF-8");

class Baidu
{

    public function Baidu()
    {

        // var_dump(1);die;

        $url = "https://tieba.baidu.com/f?ie=utf-8&kw=galgame";

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        // curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
        //规避SSL验证
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        $data = curl_exec($curl);
        $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');
        curl_close($curl);
        //echo $data;
        $this->simple($data);

    }


    public function simple($data)
    {

        $simple = new \simple_html_dom();

        $simple->load($data);
        //评论
        //  $comment = $simple->find('a');


        foreach ($simple->find("div ul li div div div div div.threadlist_abs") as $e) {
            echo $e->plaintext ."\n". "<br>";
            echo "<hr><br>";
        }


        $simple->clear();


        // var_dump($comment);die;


    }


}